package com.tps.eric.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.concurrent.CompletableFuture;

@Service
public class BatchService {

    @Async
    public CompletableFuture<Integer> processBatchTask(int taskId) {
        try {
            System.out.println("开始处理任务 " + taskId + ", 线程名称：" + Thread.currentThread().getName());
            int nextInt = new Random().nextInt(10);
            System.out.println("耗时：" + nextInt + "ms");
            Thread.sleep(nextInt); // 模拟耗时操作
            System.out.println("完成处理任务 " + taskId + ", 线程名称：" + Thread.currentThread().getName());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return CompletableFuture.completedFuture(1);
    }
}
